Aller au contenu principal

Git Notes

Init local repo to remote

Create empty repo on Github then get the repo link.

git remote add origin https://github.com/username/repo.git
git push -u origin main

Git create branch


git branch feature/new-feature-branch

# Create and switch immediately
git checkout -b feature/new-feature-branch

# git switch with create flag
git switch -c feature/new-feature-branch

After creating the branch push the branch to remote repo

git push origin feature/new-feature-branch

# If setting setting upstream flag
git push -u origin feature/new-feature-branch
remarque

-u or --set-upstream option sets tracking relationship between a local branch and a remote branch. It allows simplified commands lie git push or git pull without specifying the remote name and branch every time.

It also helps to determine default behavior for commands like git fetch, git merge, git rebase operations with no arguments.

Changing Commit Message After Push

Source

git commit --amend

or

git commit -m --amend

Enter the new commit message then

git push --force-with-lease <repo> <branch>

Undo pushed commit for edit

Get the hash of the commit then revert the commit.

git log --online

git revert <commit-hash>

# Edit the commit

git commit -m "message"
git push

Create branch